package org.example.leetCode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Administrator
 */
public class Permute {
    LinkedList<Integer> path = new LinkedList<>();
    List<List<Integer>> result;

    public List<List<Integer>> permute(int[] nums) {
        permuteArray(nums, 0);
        return result;
    }

    private void permuteArray(int[] nums, int start) {
        if (path.size() == nums.length) {
            result.add(path);
            return;
        }
        for (int i = start; i < nums.length; i++) {
            path.add(nums[i]);
            permuteArray(nums, i + 1);
            path.removeLast();
        }
    }
}
